declare const config: Chainable

const result: ChainableResult = config
  .option('foo', 123)
  .option('bar', { value: 'Hello World' })
  .option('name', 'type-challenges')
  .get()

// 期望 result 的类型是：
interface ChainableResult {
  foo: number
  bar: {
    value: string
  }
  name: string
}

type Chainable<Result extends Record<string, any> = {}> = {
  option: <K extends string, V>(key: K extends keyof Result ? V extends Result[K] ? K : never : K, value: V) => Chainable<Result & { [Key in K]: V }>
  get: () => Result;
}